import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.example.cgg.tools.time.CnDateConvertUtil;
import org.example.cgg.tools.word.WordTemplateUtil;

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class WordTemplateExport {

    public static void main(String[] args) throws Exception {
        InputStream is = WordTemplateUtil.class.getResourceAsStream("/office/word_template.docx");
        XWPFDocument doc = new XWPFDocument(is);

        Map<String, Object> map = new HashMap<>();
        map.put("id", "12345678");
        map.put("formName", "俺的沙发单位");
        map.put("departName", "查封而气温爱爱人");
        map.put("qualificationName", "暗示法请我而");
        map.put("projectName", "达芬奇二二");
        map.put("bidderCompanyName", "阿斯顿发起违反法");
        map.put("bidderQuotationAmount", 10000);
        map.put("contacts", "察维尔维尔");
        map.put("contactsPhone", "1457489652");
        map.put("today", CnDateConvertUtil.dateToCnDate(new Date()));

        WordTemplateUtil.replaceAllPlaceholders(doc, map);

        OutputStream os = Files.newOutputStream(Paths.get("D:/tmp/test-fill-" + System.currentTimeMillis() + ".docx"));
        doc.write(os);
    }
}
